﻿using Demo.OrderManager.Orders.Dto;
using Demo.ProductManager.Products.Dto;
using Demo.Store.Application.Contracts.Store.Dto;
using Volo.Abp.AutoMapper;

namespace Demo.Store.Application;

public static class StoreAutoMapperProfile
{
    /// <summary>
    /// 创建商城领域映射关系
    /// </summary>
    /// <param name="profile"></param>
    public static void CreateStoreMap(this DemoStoreApplicationAutoMapperProfile profile)
    {
        profile.CreateMap<StoreOrderCreateDto, OrderCreateDto>()
            .Ignore(x=>x.Products)
            .AfterMap((source, target) =>
            {
                target.Products = new List<ProductCountDto>();
                foreach (var productCount in source.Products)
                {
                    target.Products.Add(new ProductCountDto(productCount.ProductId, productCount.Count));
                }
            });
        profile.CreateMap<OrderDto, StoreOrderDto>();
        profile.CreateMap<OrderDetailDto, StoreOrderDetailDto>()
            .Ignore(x => x.Products);
        profile.CreateMap<ProductDto, StoreOrderProductsDto>();
        profile.CreateMap<StoreProductCreateDto, ProductDto>();
        profile.CreateMap<StoreProductDto, ProductDto>();
        profile.CreateMap<ProductDto, StoreProductDto>(); 
    }
}